function [Yij, y, prices] = loadData(n, J, dt)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function loads the data of S&P 100 stocks historical prices of
% J days, with dt optimization period, and n = 100 by default
%          only supply small n and J for testing purposes.
% S&P 100 historical data assumed to be in "data.xls"
% current price is in "dataToday.xls"
% "sheets.txt" stores the S&P 100 TICKER Names
% Historical Prices are returned
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin < 1
    n = 100; % S&P 100 stocks
    J = 500; % # of historical prices
    dt = 10; % # of days for optimization period
end

% Assume you have sheets as the sheet names stored
sheets = importdata('sheets.txt'); % import the Ticker names

prices = zeros(J+dt,n);
y = zeros(1,n);  % current stock prices
range = sprintf('G2:G%d',J+dt+1);  % range to load the data, should be
                                   % dt more days 
                                   
h = waitbar(0, '', 'Name', 'Loading Historical Data...');                                   
for i=1:n
   prices(:,i) = xlsread('data.xls', sheets{i}, range); 
   waitbar(i/n, h, sprintf('Loading Ticker %s', sheets{i}));
end
close(h);

% Now get current price
h = waitbar(0, '', 'Name', 'Loading Current Prices...');
for i=1:n
   y(i) = xlsread('dataToday.xls', sheets{i}, 'G:G');
   waitbar(i/n, h, sprintf('Loading Ticker %s', sheets{i}));
end
close(h);

% Scenario Generation
% Now we can generate the senario returns 'Yij';
pi = 1/J;  
prices = prices';
Y = repmat(y',1,J);
r = prices(:,1+dt:J+dt)./prices(:,1:J);
Yij = Y.*r;


end














